package com.arpa.wms.domain.enums;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.enums.IEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: Allen chen
 * @Date 2020/8/17
 * @Description:
 */
public enum DeliveryTypeEnum implements IEnum<String> {
    /**
     * 出库类型
     */
    OUT_SALE("0","销售出库"),
    OUT_BAOSUN("1","报损出库"),
    OUT_LINGYONG("2","领用出库"),
    OUT_LOSS("3","盘亏出库"),
    // OMS的采购退货
    PURCHASE("4", "采购退货"),
    ALLOCATION("5", "调拨出库"),
    PREPACKAGED("6", "预打包")
    ;

    /**
     * 值
     */
    private String value;

    /**
     * 描述
     */
    private String desc;

    public static DeliveryTypeEnum catchMessage(String msg) {
        DeliveryTypeEnum result = null;
        for (DeliveryTypeEnum s : values()) {
            if (s.getDesc().equals(msg)) {
                result = s;
                break;
            }
        }
        return result;
    }


    DeliveryTypeEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static String translate(String value){
        DeliveryTypeEnum item = ENUM_MAP.get(value);
        if(item != null){
            return item.getDesc();
        }
        return StrUtil.EMPTY;
    }

    private static final Map<String, DeliveryTypeEnum> ENUM_MAP = new HashMap();

    static {
        for(DeliveryTypeEnum item: values()){
            ENUM_MAP.put(item.getValue(), item);
        }

    }

    public static DeliveryTypeEnum getEnumByValue(String value) {
        return ENUM_MAP.get(value);
    }

    @Override
    public String getValue() {
        return value;
    }

    @Override
    public String toString(){
        return this.desc;
    }

    public String getDesc() {
        return desc;
    }

}
